//
//  BranchPartyOrganizTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/18.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "BranchPartyOrganizTableViewCell.h"

@interface BranchPartyOrganizTableViewCell ()
/**  图片   */
@property (strong, nonatomic) UIImageView  *actImageView;
/**  标题  */
@property (strong, nonatomic) UILabel  *actLabel;
/**  时间图片  */
@property (strong, nonatomic) UIImageView  *timeImageVIew;
/**  时间  */
@property (strong, nonatomic) UILabel  *timeLabel;
/**  人数  */
@property (strong, nonatomic) UILabel  *actNumberLabel;
/**  地点  */
@property (strong, nonatomic) UILabel  *addressLabel;
/**  地点图片  */
@property (strong, nonatomic) UIImageView  *addressImageView;
/**  活动状态  */
@property (strong, nonatomic) UILabel  *statusLabel;
@end
@implementation BranchPartyOrganizTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
        
        
        TenGrayShadowView *under = [TenGrayShadowView new];
        under.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:under];
        under.sd_layout.bottomEqualToView(self).heightIs(10 * [UIScreen zj_screenHScale]).widthIs([UIScreen zj_screenWith]).leftEqualToView(self);
    }
    return self;
}





#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.actImageView];
    [self addSubview:self.addressImageView];
    [self addSubview:self.addressLabel];
//    [self addSubview:self.statusLabel];
    [self addSubview:self.timeImageVIew];
    [self addSubview:self.timeLabel];
//    [self addSubview:self.actNumberLabel];
    [self addSubview:self.actLabel];
    
    
    self.actImageView.sd_layout
    .topSpaceToView(self,10 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self,12 * [UIScreen zj_screenWScale])
    .heightIs(90 * [UIScreen zj_screenHScale])
    .widthIs(130 * [UIScreen zj_screenWScale]);
    
    self.addressImageView.sd_layout
    .bottomEqualToView(self.actImageView)
    .leftSpaceToView(self.actImageView,10 * [UIScreen zj_screenWScale])
    .heightIs(12 * [UIScreen zj_screenHScale])
    .widthIs(12 * [UIScreen zj_screenWScale]);
    
    self.addressLabel.sd_layout
    .bottomEqualToView(self.actImageView)
    .leftSpaceToView(self.addressImageView,10 * [UIScreen zj_screenWScale])
    .heightIs(12 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
    
    self.statusLabel.sd_layout
    .bottomEqualToView(self.actImageView)
    .rightSpaceToView(self,12 * [UIScreen zj_screenWScale])
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(100 * [UIScreen zj_screenWScale]);
    
    self.timeImageVIew.sd_layout
    .bottomSpaceToView(self.addressImageView,8 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.addressImageView)
    .heightIs(12 * [UIScreen zj_screenHScale])
    .widthIs(12 * [UIScreen zj_screenWScale]);
    
    self.timeLabel.sd_layout
    .bottomSpaceToView(self.addressImageView,8 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.addressLabel)
    .heightIs(12 * [UIScreen zj_screenHScale])
    .widthIs(150 * [UIScreen zj_screenWScale]);
    
    self.actNumberLabel.sd_layout
    .bottomSpaceToView(self.addressImageView,10 * [UIScreen zj_screenHScale])
    .rightEqualToView(self.statusLabel)
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(100 * [UIScreen zj_screenWScale]);
    
    self.actLabel.sd_layout.topEqualToView(self.actImageView)
    .leftSpaceToView(self.actImageView, 10 * [UIScreen zj_screenWScale])
    .heightIs(60 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
}


#pragma mark - 私有方法
- (void)setModel:(BranchPartyOrgizationModel *)model{
    _model = model;
    NSString *urlString;
    if ([model.ORGCONCENTER_IMGPATHS containsString:@","]) {
         NSArray  *array = [model.ORGCONCENTER_IMGPATHS componentsSeparatedByString:@","];
        urlString = array[0];
    }else{
        if (model.ORGCONCENTER_IMGPATHS.length == 0) {
            urlString = @"333";
        }else{
            urlString = model.ORGCONCENTER_IMGPATHS;
        }
    }
   
    [self.actImageView sd_setImageWithURL:CREATEURL(urlString) placeholderImage:PlaceholderImage];

    NSString *address ;
    if (model.DEPTCONTACTS_ADDRESS.length != 0) {
        address = model.DEPTCONTACTS_ADDRESS;
    }else{
        address = model.DEPT_DEADDRESS;
    }
    if (address.length == 0) {
        self.addressLabel.text = @"暂无";
    }else{
        self.addressLabel.text = address;
    }
    
    if (model.MOBILE.length == 0) {
        self.timeLabel.text = @"暂无";
    }else{
        self.timeLabel.text = model.MOBILE;
    }

    
    NSString *title;
    if (model.DEPTABBREVIATION.length != 0) {
        title = model.DEPTABBREVIATION;
    }else{
        title = model.DEPT_NAME;
    }
    
    self.actLabel.attributedText = [UILabel setSpaceForLineWithText:title lineSpace:5 * [UIScreen zj_screenHScale]];
    
    
    if (model.HEIGHT < 60 * [UIScreen zj_screenHScale]) {
        self.actLabel.sd_layout.heightIs(model.HEIGHT);
        [self.actLabel updateLayout];
    }

}




#pragma mark - getter
- (UIImageView *)addressImageView{
    if (!_addressImageView) {
        _addressImageView = [UIImageView new];
        _addressImageView.contentMode = UIViewContentModeCenter;
        _addressImageView.image = [UIImage imageNamed:@"hdxq_address"];
    }
    return _addressImageView;
}


- (UIImageView *)timeImageVIew{
    if (!_timeImageVIew) {
        _timeImageVIew = [UIImageView new];
        _timeImageVIew.contentMode = UIViewContentModeCenter;
        _timeImageVIew.image = [UIImage imageNamed:@"zhibutong_phone"];
    }
    return _timeImageVIew;
}


- (UIImageView *)actImageView{
    if (!_actImageView) {
        _actImageView = [UIImageView new];
        _actImageView.contentMode = UIViewContentModeCenter;
        _actImageView.clipsToBounds = YES;
    }
    return _actImageView;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _timeLabel;
}

- (UILabel *)actNumberLabel{
    if (!_actNumberLabel) {
        _actNumberLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentRight;
            label.textColor = [UIColor themeColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _actNumberLabel;
}


- (UILabel *)statusLabel{
    if (!_statusLabel) {
        _statusLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentRight;
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _statusLabel;
}

- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _addressLabel;
}

- (UILabel *)actLabel{
    if (!_actLabel) {
        _actLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.numberOfLines = 0;
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _actLabel;
}

@end
